//import com.hmsg.health.Application;
//import org.junit.Test;
//import org.junit.runner.RunWith;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.test.context.SpringBootTest;
//import org.springframework.data.geo.Circle;
//import org.springframework.data.geo.Distance;
//import org.springframework.data.geo.GeoResults;
//import org.springframework.data.geo.Metrics;
//import org.springframework.data.geo.Point;
//import org.springframework.data.redis.connection.RedisConnectionFactory;
//import org.springframework.data.redis.connection.RedisGeoCommands;
//import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
//import org.springframework.data.redis.core.RedisTemplate;
//import org.springframework.data.redis.core.StringRedisTemplate;
//import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
//import org.springframework.test.context.junit4.SpringRunner;
//import redis.clients.jedis.GeoUnit;
//import redis.clients.jedis.JedisPoolConfig;
//import redis.clients.jedis.JedisShardInfo;
//import redis.clients.jedis.params.geo.GeoRadiusParam;
//
//import javax.annotation.Resource;
//import java.util.Date;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//
//
////@RunWith(SpringRunner.class)
////@SpringBootTest(classes = Application.class)
//public class RedisController {
//    //测量距离
////    @Autowired
//    private StringRedisTemplate redisTemplate;
//
//
//
//    private final String cityGeo = "cityGeo";
//
//
//
//    @Test
//    public void testAdd(){
////        Long addedNum = redisTemplate.opsForGeo()
////                .geoAdd(GEO_KEY,new Point(116.405285,39.904989),"北京");
////        System.out.println(addedNum);
////        Map<String, Object> map = new HashMap<String, Object>();
////        map.put("xcode", "111");
////        map.put("createtime", String.valueOf(new Date().getTime()));
////        redisTemplate.opsForHash().putAll(GEO_KEY + 1 + "_" + 1520000000, map);
//    }
//
//    //根据key 取出对应的经纬度 [Point [x=116.405283, y=39.904988], Point [x=121.472646, y=31.231705], null]
//    @Test
//    public void testGeoGet(){
//        List<Point> points = redisTemplate.opsForGeo().geoPos(cityGeo,"北京","上海","深圳");
//        if(points != null && points.size()>0){
//            for(Point point:points){
//                redisTemplate.opsForGeo().geoRemove(cityGeo,"北京");
//            }
//        }
//        System.out.println(points);
//    }
//
//    //删除
//    @Test
//    public void testAllGeoGet(){
//        JedisShardInfo jedisShardInfo = new JedisShardInfo("123.57.148.171");
//        jedisShardInfo.setPassword("IGc5YmZzTzA3PrfKRKQO");
//        StringRedisTemplate redisTemplate = new StringRedisTemplate(new JedisConnectionFactory(jedisShardInfo));
//
//        Long s = redisTemplate.opsForGeo().geoRemove(cityGeo, "北京");
//
//        System.out.println(s);
//    }
//
//
//    @Test
//    public void testRemoveGeoGet(){
//        List<Point> points = redisTemplate.opsForGeo().geoPos(cityGeo,"北京","上海","深圳");
//        System.out.println(points);
//    }
//
//    //返回两个地方的距离，可以指定单位，比如米m，千米km，英里mi，英尺ft
//    @Test
//    public void testDist(){
//        Distance distance = redisTemplate.opsForGeo()
//                .geoDist(cityGeo,"北京","上海", RedisGeoCommands.DistanceUnit.KILOMETERS);
//        System.out.println(distance);
//    }
//
//    //根据给定的经纬度，返回半径不超过指定距离的元素
//    @Test
//    public void testNearByXY(){
//        JedisShardInfo jedisShardInfo = new JedisShardInfo("123.57.148.171");
//        jedisShardInfo.setPassword("IGc5YmZzTzA3PrfKRKQO");
//        StringRedisTemplate redisTemplate = new StringRedisTemplate(new JedisConnectionFactory(jedisShardInfo));
//
//
//        //longitude,latitude
//        double multiplier = Metrics.KILOMETERS.getMultiplier();
//        System.out.println(multiplier);
//        Circle circle = new Circle(new Point(116.423887,39.907396), new Distance(2, RedisGeoCommands.DistanceUnit.KILOMETERS));
//        RedisGeoCommands.GeoRadiusCommandArgs args = RedisGeoCommands.GeoRadiusCommandArgs.newGeoRadiusArgs().includeDistance().includeCoordinates().sortAscending().limit(2);
//        GeoResults<RedisGeoCommands.GeoLocation<String>> results = redisTemplate.opsForGeo().geoRadius(cityGeo,circle,args);
//
//        System.out.println(results);
//
//    }
//    //返回的是geohash值
//    @Test
//    public void testGeoHash(){
//        List<String> results = redisTemplate.opsForGeo()
//                .geoHash(cityGeo,"北京","上海","深圳");
//        System.out.println(results);
//    }
//
//
//    @Test
//    public void testNearByXY1(){
//        //longitude,latitude
//
//        System.out.println(cityGeo);
//
////        Circle circle = new Circle(116.405285,39.904989, Metrics.KILOMETERS.getMultiplier());
////        RedisGeoCommands.GeoRadiusCommandArgs args = RedisGeoCommands.GeoRadiusCommandArgs.newGeoRadiusArgs().includeDistance().includeCoordinates().sortAscending().limit(5);
////        GeoResults<RedisGeoCommands.GeoLocation<String>>  results = redisTemplate.opsForGeo()
////                .geoRadius(cityGeo,circle,args);
////        System.out.println(results);
//    }
//     @Test
//    public void test1(){
//         //对文章内容进行截取
//         String content = "我的好文章内容是实话实说上海市";
//         if(content != null && content.length()<=10){
//             content=content;
//         }else{
//             content=content.substring(0,10);
//         }
//         System.out.println(content);
//     }
//
//}
